package com.usooft.metaTalent.core.system.service.basic;

import com.usooft.metaTalent.core.system.entity.Dict;
import com.usooft.metaTalent.core.system.entity.DictItem;
import com.usooft.metaTalent.core.system.query.DictItemQuery;
import com.usooft.metaTalent.core.system.service.DictItemService;
import com.usooft.metaTalent.core.system.service.base.BaseDictItemService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@RequiredArgsConstructor
public class BasicDictItemService extends BaseDictItemService implements DictItemService {

    @Override
    @Transactional
    public DictItem create(Dict dict, String value) {
        return internalAdd(dict.getId(), value);
    }

    @Override
    @Transactional
    public void edit(DictItem dictItem, String value) {
        dictItem.setValue(value);
        internalUpdate(dictItem);
    }

    @Override
    @Transactional
    public List<? extends DictItem> listByDict(Dict dict) {
        return list(DictItemQuery.builder()
                .filter(DictItemQuery.Filter.builder()
                        .dictIdIs(dict.getId())
                        .build())
                .build());
    }

    // region 自动生成
    // endregion
}